package hn.sigit.view;

import hn.sigit.dao.hnd.cadastre.HND_BuildingMaterialDAO;
import hn.sigit.model.hnd.cadastre.HND_BuildingMaterial;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Name("buildingMaterialHelper")
@Scope(value = ScopeType.CONVERSATION)
@AutoCreate
public class BuildingMaterialHelper extends MantHelper<HND_BuildingMaterial> {
	private static final long serialVersionUID = 1L;
	
	protected final String BY_NAME = "0";
	

	@Override
	public String addNew() {
		setSelected(new HND_BuildingMaterial());
		return super.addNew();
	}


	@Override
	public String quickSearch() {
		searchText = searchText.trim();
		List<HND_BuildingMaterial> searchResultList = new ArrayList<HND_BuildingMaterial>();
		
		if (searchSelector.equals(BY_NAME))
			searchResultList = HND_BuildingMaterialDAO.loadBuildingTypesByName(searchText);
		
		if (searchResultList.size() == 0) {
			FacesContext.getCurrentInstance().addMessage("",
					new FacesMessage(
							FacesMessage.SEVERITY_INFO,
							resBundle.loadMessage("txt.no_search_results"),
							""
					)
			);
		}

		setEntityList(searchResultList);
		
		return null;
	}


	public String getBY_NAME() {
		return BY_NAME;
	}
}
